package com.nintendo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nintendo.bean.ChatRecord;
import com.nintendo.mapper.ChatRecordMapper;
import com.nintendo.service.ChatRecordService;
import com.nintendo.utils.ChatTypeEnum;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ChatRecordServiceImpl extends ServiceImpl<ChatRecordMapper, ChatRecord> implements ChatRecordService {
    @Resource
    private ChatRecordMapper chatRecordMapper;
    @Override
    public void saveChatRecord(String username, String message, ChatTypeEnum chatType) {
        ChatRecord chatRecord = new ChatRecord();
        chatRecord.setFamilyMember(username);
        chatRecord.setContent(message);
        chatRecord.setChatType(chatType.type);
        chatRecord.setChatTime(LocalDateTime.now());
        chatRecordMapper.insert(chatRecord);
    }

    @Override
    public List<ChatRecord> getChatRecord(String username) {
        LambdaQueryWrapper<ChatRecord> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.eq(ChatRecord::getFamilyMember, username);
        return chatRecordMapper.selectList(queryWrapper);
    }
}
